<?php 
    @session_start();
    include_once("../app/connection.php");
    include_once("check_user.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<style type="text/css">
    body{background: #ddd;}
    table td{width: 150px; padding: 5px; text-align: center}
    table th{padding: 5px; background: #247CB9; color: #fff}
</style>
</head>

<body>
<div id="main" style="width: 1400px; background: #fff; margin: 0 auto; position: relative;">
    <div id="header" style="padding: 10px; background: #247CB9; color: #fff;; text-align: center; margin-bottom: 10px;
        height: 50px; line-height: 50px;">
        <span style="font-size: 24pt;"><b>THỜI KHÓA BIỂU</b></span>        
    </div><br />
    
<?php
	if($is_sv)
	{
        $sql = mysql_query("SELECT * FROM sinhvien WHERE MSSV = '$user'");
        $row = mysql_fetch_assoc($sql);
?>
        <center>
            <span style="font-size: 18pt;"><i>
                <b>MSSV: </b><?php echo $row['MSSV']; ?> - <b>Họ và tên: </b><?php echo $row['HOTEN']; ?>
                - <b>Lớp: </b><?php echo $row['MAKHOA'].$row['KHOAHOC']; ?>
            </i></span> <br /><br />
        </center>              
    	<center><table border="1" style="border-collapse:collapse;" id="tkb_sv">
        	<tr><th></th><th>Thứ 2</th><th>Thứ 3</th><th>Thứ 4</th><th>Thứ 5</th><th>Thứ 6</th><th>Thứ 7</th></tr>
            <tr><th style="width: 30px;">1</th><td id="c1_t2"></td><td id="c1_t3"></td><td id="c1_t4"></td><td id="c1_t5"></td><td id="c1_t6"></td><td id="c1_t7"></td></tr>
            <tr><th>2</th><td id="c2_t2"></td><td id="c2_t3"></td><td id="c2_t4"></td><td id="c2_t5"></td><td id="c2_t6"></td><td id="c2_t7"></td></tr>
            
            <tr><td colspan="7" style="background: #247CB9; height: 10px; padding: 0;">&nbsp;</td></tr>
            
            <tr><th>3</th><td id="c3_t2"></td><td id="c3_t3"></td><td id="c3_t4"></td><td id="c3_t5"></td><td id="c3_t6"></td><td id="c3_t7"></td></tr>
            <tr><th>4</th><td id="c4_t2"></td><td id="c4_t3"></td><td id="c4_t4"></td><td id="c4_t5"></td><td id="c4_t6"></td><td id="c4_t7"></td></tr>
        </table></center>
        <span>
        <br /> Thời gian: <br />
        	Ca 1 : 7h30 - 9h45 <br/>
            Ca 2 : 10h - 11h30 <br />
            Ca 3 : 13h - 14h30 <br />
            Ca 4 : 14h45 - 16h45 
            
        </span>
        
        <?php
        
        $today = date('Y-m-d');
      
		$cm = "SELECT * FROM dangky, lop, monhoc, hocky WHERE monhoc.MAMONHOC = dangky.MAMONHOC AND dangky.MAMONHOC = lop.MAMONHOC 
        AND dangky.MALOP = lop.MALOP AND dangky.HOCKY = lop.HOCKY AND dangky.NAM = lop.NAM AND dangky.HOCKY = hocky.HOCKY
        AND dangky.NAM = hocky.NAM AND MSSV='$user' AND NGAYBATDAU <= '$today' AND NGAYKETTHUC >= '$today'";
		$r = mysql_query($cm,$connect) or die(mysql_error($connect));
		//$rs = mysql_fetch_array($r);
		while($rs = mysql_fetch_array($r))
		{
			//echo $rs['mssv']." ".$rs['mamh']." ".$rs['malop_mh']." ".$rs['tenmh']." ".$rs['ca']." ".$rs['thu']."<br />";
			$ca = $rs['CA']; 
			$thu = $rs['THU'];
			$mh = $rs['MAMONHOC'].".".$rs['MALOP'];
			$tmh = $rs['TENMONHOC'];
			$ph = "P.".$rs['PHONG'];
			if($ca == '1')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t2\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '3')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t3\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '4')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t4\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '5')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t5\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '6')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t6\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '7')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t7\").innerHTML = x;		
                    </script>";
				}
			} // het ca 1
			else if($ca == '2')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t2\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '3')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t3\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '4')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t4\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '5')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t5\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '6')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t6\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '7')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c2_t7\").innerHTML = x;		
                    </script>";
				}
			} // het ca 2
			else if($ca == '3')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t2\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '3')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t3\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '4')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t4\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '5')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t5\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '6')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t6\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '7')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t7\").innerHTML = x;		
                    </script>";
				}
			} // het ca 3
			else if($ca == '3')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t2\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '3')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t3\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '4')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t4\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '5')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t5\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '6')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t6\").innerHTML = x;		
                    </script>";
				}
				else if($thu == '7')
				{
					echo "<script type='text/javascript'>
					
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c4_t7\").innerHTML = x;		
                    </script>";
				}
			} // het ca 4
			else if($ca == '1 - 2')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
						document.getElementById(\"c1_t2\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t2\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t2\").innerHTML = x;
                    </script>";
				}
				else if($thu == '3')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c1_t3\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t3\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t3\").innerHTML = x;
                    </script>";
				}
				else if($thu == '4')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c1_t4\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t4\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t4\").innerHTML = x;
                    </script>";
				}
				else if($thu == '5')
				{
					  echo "<script type='text/javascript'>
						document.getElementById(\"c1_t5\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t5\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t5\").innerHTML = x;
                    </script>";
				}
				else if($thu == '6')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c1_t6\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t6\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t6\").innerHTML = x;
                    </script>";
				}
				else if($thu == '7')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c1_t7\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c2_t7\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c1_t7\").innerHTML = x;
                    </script>";
				}
			} // het ca 1 - 2
			else if($ca == '3 - 4')
			{
				if($thu == '2')
				{
				 echo "<script type='text/javascript'>
						document.getElementById(\"c3_t2\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t2\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t2\").innerHTML = x;
                    </script>";
				}
				else if($thu == '3')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c3_t3\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t3\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t3\").innerHTML = x;
                    </script>";
				}
				else if($thu == '4')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c3_t4\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t4\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t4\").innerHTML = x;
                    </script>";
				}
				else if($thu == '5')
				{
					  echo "<script type='text/javascript'>
						document.getElementById(\"c3_t5\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t5\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t5\").innerHTML = x;
                    </script>";
				}
				else if($thu == '6')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c3_t6\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t6\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t6\").innerHTML = x;
                    </script>";
				}
				else if($thu == '7')
				{
					 echo "<script type='text/javascript'>
						document.getElementById(\"c3_t7\").setAttribute(\"rowspan\",2);
						document.getElementById(\"c4_t7\").remove(0);
                        var x = \"".$mh.'<br/>'.$tmh."<br/>".$ph."\";
						document.getElementById(\"c3_t7\").innerHTML = x;
                    </script>";
				}
			} // het ca 3 - 4			
		}
	}
	else
	{
		echo "Vui lòng đăng nhập bằng tài khoản Sinh viên!";
		echo "<meta http-equiv=\"refresh\" content=\"2; URL = ../index.php\">";
	}
?>
    <div id="nv_home" style="position: absolute; top: 0; left: 10px; height: 70px; line-height: 70px">
        <b><a href="../" style="text-decoration: none; color: #fff;">TRANG CHỦ</a></b>
    </div>
</div>

</body>
</html>